/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.ex;

import java.io.IOException;
import java.util.Properties;

/**
 * <p>Project: javaseapp - Ex02
 * <p>Powered by webrx On 2021-09-01 09:03:58
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Ex02 {
    public static void main(String[] args) {
        var is = Thread.currentThread().getContextClassLoader().getResourceAsStream("db.properties");
        var prop = new Properties();
        try {
            prop.load(is);
            System.out.println(prop.get("db.driver"));
            System.out.println(prop.getProperty("db.username"));
            System.out.println(prop.getProperty("db.password", "123456"));
            //prop.values() Collection<Object>
            prop.values().forEach(System.out::println);

            //prop.keys() Enumeration<Object>
            var e = prop.keys();
            while (e.hasMoreElements()) {
                String key = e.nextElement().toString();
                System.out.println(key);
                System.out.println(prop.getProperty(key));
            }

            //prop.keySet() Set<Object>
            prop.keySet().forEach(System.out::println);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
